home *** CD-ROM | disk | FTP | other *** search
AmigaBASIC Source Code | 1987-05-08 | 2.9 KB | 112 lines | [MSBC/MSBB] |
- 'Text Edit Demo
- 'By Dave Kelly
- 'teRec Wrap by Dave Smith
- '©MacTutor 1987
-
- OriginalEditString$="This is the first string."
- endofstring=LEN(OriginalEditString$)
- ' Set up rectangle for TEUPDATE call
- rect%(0)=20:rect%(1)=10:rect%(2)=200:rect%(3)=460
-
- WINDOW 1,"Text Edit Demo",(15,40)-(495,330),2
- EDIT FIELD 1,OriginalEditString$,(10,20)-(460,200),6,1
- PRINT "Click mouse button outside of edit field or type …"
- LOCATE 15,1
- PRINT "The Text Edit field has been created. (EDIT FIELD statement)"
- LOCATE 17,1:PRINT "TextEdit Buffer:"
- oldkey$=""
- GOSUB wrap: REM make textedit wrap to view rectangle
- <0xb9a7b60,0xb9a6010> endofstring+1,endofstring+1,WINDOW(6)
- GOSUB eventloop
-
- 'Set the edit field text to a new string
- NewEditString$="This the second string. (replaced old string)"
- <0xb9a7cc0,0xb9a6010> SADD(NewEditString$),LEN(NewEditString$),WINDOW(6)
-
- 'Re-draw the edit field (needs to be re-drawn after setting new text)…
- <0xb9a7dd0,0xb9a6010> VARPTR(rect%(0))
- <0xb9a7eb0,0xb9a6010> VARPTR(rect%(0)),WINDOW(6)
- LOCATE 15,1
- PRINT "The Text Edit field has been set to a new string (TESETTEXT call)."
- GOSUB eventloop
-
- 'Set the selection range…
- <0xb9a8010,0xb9a6010> 1,6,WINDOW(6)
- LOCATE 15,1
- PRINT "The text has been selected… selection range";STRING$(50," ")
- PRINT "is from before character 1 until before character 6. (TESETSELECT call)"
- GOSUB eventloop
-
- 'Delete the selected text…
- <0xb9a8250,0xb9a6010> WINDOW(6)
- LOCATE 15,1
- PRINT "The selected text has been deleted. (TEDELETE call)";STRING$(30," ")
- PRINT STRING$(150," ")
- GOSUB eventloop
-
- 'De-activate the edit field…
- <0xb9a8450,0xb9a6010> WINDOW(6)
- LOCATE 15,1
- PRINT "The text has been deactivated (TEDEACTIVATE call)"
- GOSUB eventloop
-
- 'Re-activate the edit field...
- <0xb9a8600,0xb9a6010> WINDOW(6)
- LOCATE 15,1
- PRINT "The text has been activated (TEACTIVATE call)";STRING$(10," ")
- GOSUB eventloop
-
- 'Insert new text at the insertion point…
- TextToInsert$="-This text was inserted-"
- <0xb9a8800,0xb9a6010> SADD(TextToInsert$),LEN(TextToInsert$),WINDOW(6)
- LOCATE 15,1
- PRINT "Text has been inserted at the insertion point. (TEINSERT call)";STRING$(20," ")
- GOSUB eventloop
-
- quit:
- EDIT FIELD CLOSE 1
- CLS: END
-
- eventloop:
- WHILE MOUSE(0)<>1
- GOSUB TextEdit
- key$=EDIT$(1)
- IF key$<>oldkey$ THEN GOSUB processtext
- oldkey$=key$
- WEND
- RETURN
-
- processtext:
- chartyped$=RIGHT$(key$,1) :REM how do you get last char typed?
- LOCATE 17,18
- PRINT SPACE$(4);
- LOCATE 17,18
- IF chartyped$<>CHR$(13) THEN PRINT chartyped$ :ELSE PRINT "CR"
- RETURN
-
- TextEdit:
- myHandle#=WINDOW(6)
- LOCATE 17,24:PRINT myHandle#
- ptr1=PEEK(myHandle#+3)
- ptr2=PEEK(myHandle#+2)
- ptr3=PEEK(myHandle#+1)
- ptr4=PEEK(myHandle#+0)
- ptr#=(ptr3*(65536)) + (ptr2*256) + ptr1
- telength1 = PEEK(ptr#+61)
- teLength2=PEEK(ptr#+60)
- teLength = teLength2*256+telength1
- LOCATE 17,35:PRINT ptr#
- LOCATE 17,45:PRINT teLength
- RETURN
-
- wrap:
- GOSUB TextEdit : REM get teRec address
- REM poke new values in teRec
- crOnlyAdd#=ptr#+72
- cronly%=0:POKE crOnlyAdd#,0 :REM turn OFF cronly
- FOR i=0 TO 7
- POKE ptr#+8+i,PEEK(ptr#+i): REM dest rect = view rect
- NEXT i
- <0xb9a95b0,0xb9a6010> WINDOW(6): REM re-do line endings
- RETURN
-